<!doctype html>
<html lang="en">

<head>
    <title>医院</title>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
        integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
    <link rel="stylesheet" href="/css/bg1.css">
</head>

<body>
    <div id="app">
        <nav class="navbar navbar-expand-md  navbar-dark" style="background-color: #0991f3;">
            <a class="navbar-brand" href="#">荔枝医院 🏥 </a>
            <div class="collapse navbar-collapse" id="collapsibleNavId">

                <ul class="navbar-nav mr-auto mt-2 mt-lg-0">

                    <li class="nav-item active ml-3">
                        <a class="nav-link" href="#">首页<span class="sr-only">(current)</span></a>
                    </li>
                    <li class="nav-item ml-3">
                        <a class="nav-link" href="#">文件</a>
                    </li>

                    <li class="nav-item dropdown ml-3">
                        <a class="nav-link dropdown-toggle" href="#" id="dropdownId" data-toggle="dropdown"
                            aria-haspopup="true" aria-expanded="false">编辑</a>

                        <div class="dropdown-menu" aria-labelledby="dropdownId">
                            <a class="dropdown-item" href="#">撤销</a>
                            <a class="dropdown-item" href="#">恢复</a>
                            <a class="dropdown-item" href="#">剪切</a>
                            <a class="dropdown-item" href="#">复制</a>
                        </div>
                    </li>
                    <li class="nav-item dropdown ml-3">
                        <a class="nav-link dropdown-toggle" href="#" id="dropdownId" data-toggle="dropdown"
                            aria-haspopup="true" aria-expanded="false">选择</a>

                        <div class="dropdown-menu" aria-labelledby="dropdownId">
                            <a class="dropdown-item" href="#">撤销</a>
                            <a class="dropdown-item" href="#">恢复</a>
                            <div class="dropdown-divider"></div>
                            <a class="dropdown-item" href="#">剪切</a>
                            <a class="dropdown-item" href="#">复制</a>
                        </div>
                    </li>
                </ul>
                <form class="form-inline my-2 my-lg-0">
                    <input class="form-control mr-sm-2" type="text" placeholder="Search">
                    <button class="btn btn-danger my-2 my-sm-0" type="submit">Search</button>
                </form>
            </div>
        </nav>

        <div class="jumbotron jumbotron-fluid py-3 bg1">
            <div class="container">

                <h1 class="display-4">线上挂号系统</h1>
                <p class="lead">荔枝医院</p>
            </div>

            <nav class="breadcrumb">
                <a class="breadcrumb-item" href="index.html">科室导航</a>
                <a class="breadcrumb-item" href="keshi.html">产科排班</a>
                <span class="breadcrumb-item active">就诊人管理</span>
                <a class="breadcrumb-item" href="appointmentinfo.html">我的预约信息</a>
            </nav>
        </div>

        <div class="container">
            <h1 class="font-weight-light h2 mb-4 offset-1">就诊人管理</h1>

            <div class="row mb-3">
                <div class="offset-1 col-md-2">
                    <button class="btn btn-success" data-toggle="modal" data-target="#modelId">新增就诊人</button>
                </div>
            </div>

            <div class="modal fade" id="modelId" tabindex="-1" role="dialog" aria-labelledby="modelTitleId"
                aria-hidden="true">
                <div class="modal-dialog" role="document">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h5 class="modal-title">就诊人添加</h5>
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                <span aria-hidden="true">&times;</span>
                            </button>
                        </div>
                        <div class="modal-body">
                            <div class="container-fluid">

                                <div class="form-group row">
                                    <label for="name" class="col-sm-3 mt-2">姓名</label>
                                    <input type="text" v-model="newpatient.name" class="col-sm-9 form-control"
                                        name="name" id="name" aria-describedby="helpId" placeholder="请输入姓名">
                                </div>
                                <div class="form-group row">
                                    <label for="cardId" class="col-sm-3 mt-2">身份证</label>
                                    <input type="text" v-model="newpatient.idCard" class="col-sm-9 form-control"
                                        name="cardId" id="cardId" aria-describedby="helpId" placeholder="请输入身份证">
                                </div>
                                <div class="form-group row">
                                    <label for="tel" class="col-sm-3 mt-2">手机</label>
                                    <input type="text" v-model="newpatient.phone" class="col-sm-9 form-control"
                                        name="tel" id="tel" aria-describedby="helpId" placeholder="请输入手机号">
                                </div>
                            </div>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
                            <button type="button" class="btn btn-primary" @click="addPatient()"
                                data-dismiss="modal">添加</button>
                        </div>
                    </div>
                </div>
            </div>



            <div class="modal fade" id="modelEdit" tabindex="-1" role="dialog" aria-labelledby="modelTitleId"
                aria-hidden="true">
                <div class="modal-dialog" role="document">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h5 class="modal-title">就诊人添加</h5>
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                <span aria-hidden="true">&times;</span>
                            </button>
                        </div>
                        <div class="modal-body">
                            <div class="container-fluid">

                                <div class="form-group row">
                                    <label for="name" class="col-sm-3 mt-2">姓名</label>
                                    <input type="text" v-model="editpatient.name" class="col-sm-9 form-control"
                                        name="name" id="name" aria-describedby="helpId" placeholder="请输入姓名">
                                </div>
                                <div class="form-group row">
                                    <label for="cardId" class="col-sm-3 mt-2">身份证</label>
                                    <input type="text" v-model="editpatient.idCard" class="col-sm-9 form-control"
                                        name="cardId" id="cardId" aria-describedby="helpId" placeholder="请输入身份证">
                                </div>
                                <div class="form-group row">
                                    <label for="tel" class="col-sm-3 mt-2">手机</label>
                                    <input type="text" v-model="editpatient.phone" class="col-sm-9 form-control"
                                        name="tel" id="tel" aria-describedby="helpId" placeholder="请输入手机号">
                                </div>
                            </div>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
                            <button type="button" class="btn btn-primary" @click="updatePatient()"
                                data-dismiss="modal">添加</button>
                        </div>
                    </div>
                </div>
            </div>

            <div class="row">
                <table class="table table-striped table-hover offset-1 col-md-10">
                    <thead>
                        <tr>
                            <th>姓名</th>
                            <th>身份证号</th>
                            <th>手机号</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr v-for="(patient, index) in patientArr" :key="index">
                            <td>{{patient.name}}</td>
                            <td>{{patient.id_card}}</td>
                            <td>{{patient.phone}}</td>
                            <td>
                                <button class="btn btn-warning" @click="edit(patient)" data-toggle="modal"
                                    data-target="#modelEdit">编辑</button>
                                <button class="btn btn-danger" @click="del(patient.id)">删除</button>
                            </td>
                        </tr>

                    </tbody>
                </table>
            </div>
        </div>



    </div>

    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
        integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
        crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"
        integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1"
        crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"
        integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM"
        crossorigin="anonymous"></script>
</body>

</html>
<script>
    var url = `http://120.24.192.41:8080`;
    new Vue({
        el: "#app",
        data() {
            return {
                patientArr: [],
                editpatient: {},
                newpatient: {},
                depart: null
            }
        },
        mounted() {
            this.getallPatient();
            this.depart = JSON.parse(sessionStorage.getItem("curDepart"));
        },
        methods: {
            getallPatient() {
                axios.get(`${url}/api/patient`)
                    .then((response) => {
                        this.patientArr = response.data;
                    })
                    .catch(function (error) {
                    })
            },
            addPatient() {
                axios.post(`${url}/api/patient`, this.newpatient)
                    .then((response) => {
                        let flag = response.data;
                        if (flag) {
                            alert("添加成功！");
                            this.getallPatient();
                        }
                    })
                    .catch(function (error) {
                    })
            },
            updatePatient() {
                axios.put(`${url}/api/patient`, this.editpatient)
                    .then((response) => {
                        if (response.data) {
                            alert("修改成功！");
                            this.getallPatient();
                        } else {
                            alert("修改失败！");
                        }
                    })
                    .catch(function (error) {
                    })
            },
            edit(patient) {
                this.editpatient = {
                    id: patient.id,
                    name: patient.name,
                    phone: patient.phone,
                    state: patient.state,
                    idCard: patient.id_card
                }
                console.log(this.editpatient);
            },
            del(id) {
                if (confirm("是否确定删除" + id + "这个就诊人！")) {
                    axios.put(`${url}/api/patient/${id}`)
                        .then((response) => {
                            if (response.data) {
                                alert("删除成功！");
                                this.getallPatient();
                            } else {
                                alert("删除失败");
                            }
                        })
                        .catch(function (error) {
                        })
                }

            }

        },
    })
</script>